import book.Book;
import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.ArrayList;
import java.util.Scanner;
public class BookMain {
    public static void main(String[] args) {
        BookList bookList = new BookList();
        User user = login();
        while (true) {
            int choice = user.DoUser();
            //使用choice调用方法数组对应下标方法的操作...
            if(choice < user.ioPerations.length) {
                user.ioPerations[choice].work(bookList);
            }else {
                System.out.println("选项输入错误,请重新输入");
            }
        }
    }
    public static User login() {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入您的名字:");
        String name = scan.next();
        while(true) {
            System.out.println("请输入您的身份:");
            System.out.println("1: 管理员 2: 普通用户");
            int use = scan.nextInt();
            if (use == 1) {
                return new AdminUser(name);
            } else if (use == 2) {
                return new NormalUser(name);
            } else {
                System.out.println("输入错误");
                continue;
            }
        }
    }
}
